<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户信息</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 头部搜索 -->
      <el-row :gutter="10">
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="100px">
              <el-form-item label="邮箱：">
                <el-input
                  v-model="queryinfo.userEmail"
                  clearable
                  placeholder="请输入邮箱"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
        <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="80px">
              <el-form-item label="手机号：">
                <el-input
                  v-model="queryinfo.userTel"
                  clearable
                  placeholder="请输入手机号"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col>

        <!-- <el-col :span="5">
          <div class="grid-content bg-purple">
            <el-form label-width="100px">
              <el-form-item label="交易所账号：">
                <el-input
                  v-model="queryinfo.jysUser"
                  clearable
                  placeholder="请输入交易所账号"
                  @clear="getmsgList"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
        </el-col> -->
        <el-button type="primary" icon="el-icon-search" @click="getmsgList"
          >搜索</el-button
        >

        <el-button
          type="warning"
          ref="Freeze"
          icon="el-icon-edit"
          @click="PledEntering"
        >
          批量分配额度
        </el-button>
      </el-row>
      <!-- <el-row>
        <el-col class="restyle" :span="4">总注册人数:{{countALL}}</el-col>
        <el-col class="restyle" :span="4">当前注册人数:{{countByToDay}}</el-col>
        <el-col class="restyle" :span="4">有效用户人数:{{countByIsValid}}</el-col>
      </el-row> -->
      <!-- 审核数据列表 -->
      <template>
        <el-table :data="tableData" stripe border style="width: 100%">
          <el-table-column type="index" label="#"> </el-table-column>
          <el-table-column prop="id" label="ID" width="80"> </el-table-column>
          <el-table-column prop="userTel" label="手机号码"> </el-table-column>
          <el-table-column prop="userEmail" label="邮箱"> </el-table-column>
          <el-table-column label="账户状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isFreeze === true">冻结</span>
              <span v-else>正常</span>
            </template>
          </el-table-column>
          <el-table-column prop="isSm" label="实名状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isSm === true">已实名</span>
              <span v-else>未实名</span>
            </template>
          </el-table-column>
          <el-table-column prop="isTb" label="提币状态">
            <template slot-scope="scope">
              <span v-if="scope.row.isTb === true">冻结</span>
              <span v-else>正常</span>
            </template>
          </el-table-column>
          <el-table-column prop="gmNum" label="通用额度"> </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div style="margin-bottom: 5px">
                <el-button
                  :type="scope.row.isTb === false ? 'primary' : 'success'"
                  size="mini"
                  ref="Tb"
                  @click="Tbsubmit(scope.row.id, scope.row.isTb)"
                >
                  {{ scope.row.isTb === false ? "提币冻结" : "提币解冻" }}
                </el-button>
              </div>
              <div style="margin-bottom: 5px">
                <el-button
                  :type="scope.row.isFreeze === true ? 'success' : 'primary'"
                  size="mini"
                  ref="Freeze"
                  @click="Freezesubmit(scope.row.id, scope.row.isFreeze)"
                >
                  {{ scope.row.isFreeze === false ? "账户冻结" : "账户解冻" }}
                </el-button>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="isTb" label="查看资产">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                ref="Freeze"
                icon="el-icon-view"
                @click="lookzc(scope.row.id)"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="" label="资产录入">
            <template slot-scope="scope">
              <el-button
                type="warning"
                size="mini"
                ref="Freeze"
                icon="el-icon-edit"
                @click="entering(scope.row.id)"
              >
                录入
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="录入记录">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                ref="Freeze"
                icon="el-icon-view"
                @click="enteringInfo(scope.row.id)"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="" label="额度调整">
            <template slot-scope="scope">
              <el-button
                type="warning"
                size="mini"
                ref="Freeze"
                icon="el-icon-edit"
                @click="edEntering(scope.row.id)"
              >
                录入
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="账单明细">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                ref="Freeze"
                icon="el-icon-view"
                @click="lookZd(scope.row.id)"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="" label="通用额度设置">
            <template slot-scope="scope">
              <el-button
                type="warning"
                size="mini"
                ref="Freeze"
                icon="el-icon-edit"
                @click="TYEDset(scope.row.id)"
              >
                录入
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30]"
        :page-size="queryinfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 查看资产 -->
    <el-dialog title="查看资产" :visible.sync="dialogVisible" width="50%">
      <el-table :data="zcTableData" stripe border style="width: 100%">
        <el-table-column prop="userId" label="ID" width="80"> </el-table-column>
        <el-table-column prop="tokenName" label="币种名称"> </el-table-column>
        <el-table-column prop="ldToken" label="流动数量"> </el-table-column>
        <el-table-column prop="djToken" label="冻结数量"> </el-table-column>
        <el-table-column prop="gmNum" label="额度"> </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 录入记录 -->
    <el-dialog title="录入记录" :visible.sync="lrdialogVisible" width="50%">
      <el-table :data="lrTableData" stripe border style="width: 100%">
        <el-table-column prop="id" label="ID"> </el-table-column>
        <el-table-column prop="createTime" label="时间"> </el-table-column>
        <el-table-column prop="gxequity" label="数量"> </el-table-column>
        <el-table-column label="操作类型">
          <template slot-scope="scope">
            <span v-if="scope.row.isJj">减</span>
            <span v-else>加</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="币种"> </el-table-column>
        <el-table-column prop="yy" label="原因"> </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 账单明细 -->
    <el-dialog title="账单明细" :visible.sync="ZddialogVisible" width="60%">
      <el-table :data="zdTableData" stripe border style="width: 100%">
        <el-table-column prop="id" label="ID" width="80"> </el-table-column>
        <el-table-column prop="coinName" label="币种名称"> </el-table-column>
        <el-table-column prop="formNum" label="操作前"> </el-table-column>
        <el-table-column prop="toNum" label="操作后"> </el-table-column>
        <el-table-column prop="" label="操作金额">
          <template slot-scope="scope">
            <span>{{ scope.row.changeType }}{{ scope.row.tokenNum }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="typeName" label="类型"> </el-table-column>
        <el-table-column prop="createTime" label="时间"> </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 余额录入   -->
    <el-dialog
      title="余额录入"
      :visible.sync="LRdialogVisible"
      @close="colseDialog"
      width="50%"
    >
      <el-row>
        <template>
          <el-select
            v-model="YEqueryinfo.coinId"
            placeholder="请选择币种"
            size="medium"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenZh"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row>
        <template>
          <el-select
            v-model="YEqueryinfo.isWay"
            placeholder="请选择操作类型"
            size="medium"
          >
            <el-option
              v-for="item in isWays"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row
        ><el-input
          v-model="YEqueryinfo.token"
          placeholder="请输入数量"
        ></el-input
      ></el-row>
      <el-row>
        <el-input
          v-model="YEqueryinfo.tokenyy"
          placeholder="请输入原因"
        ></el-input>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="GetCode()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 输入验证框 -->
    <el-dialog
      title="输入验证码"
      :visible.sync="centerDialog"
      width="25%"
      @close="colseDialog"
    >
      <el-row>
        <el-col :span="5" style="line-height: 40px">输入验证码:</el-col>
        <el-col :span="12">
          <el-input
            v-model="YEqueryinfo.codes"
            placeholder="请输入内容"
          ></el-input
        ></el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 额度调整 -->
    <el-dialog
      title="额度调整"
      :visible.sync="EddialogVisible"
      width="50%"
      @close="colseDialog"
    >
      <el-row>
        <template>
          <el-select
            v-model="Edueryinfo.coinId"
            placeholder="请选择币种"
            size="medium"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenZh"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row>
        <template>
          <el-select
            v-model="Edueryinfo.jj"
            placeholder="请选择操作类型"
            size="medium"
          >
            <el-option
              v-for="item in isJJ"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row
        ><el-input
          v-model="Edueryinfo.gnNum"
          placeholder="请输入数量"
        ></el-input
      ></el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="Edsubmit()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 批量调整额度 -->
    <el-dialog
      title="批量调整额度"
      :visible.sync="PlEddialogVisible"
      width="50%"
      @close="colseDialog"
    >
      <!-- <el-row>
        <template>
          <el-select
            v-model="PlEdueryinfo.coinId"
            placeholder="请选择币种"
            size="medium"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenZh"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </template>
      </el-row> -->
      <el-row>
        <template>
          <el-select
            v-model="PlEdueryinfo.jj"
            placeholder="请选择操作类型"
            size="medium"
          >
            <el-option
              v-for="item in isJJ"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row>
        <template>
          <el-select
            v-model="PlEdueryinfo.type"
            placeholder="请选择添加类型"
            size="medium"
          >
            <el-option
              v-for="item in isTel"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row
        ><el-input
          v-model="PlEdueryinfo.values"
          placeholder="请输入手机号(多个用英文逗号隔开例：183XXXXXXXX,183XXXXXXXX)"
        ></el-input
      ></el-row>
      <el-row
        ><el-input
          v-model="PlEdueryinfo.gmNum"
          placeholder="请输入数量"
        ></el-input
      ></el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="PlEdsubmit()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 通用额度设置 -->
    <el-dialog
      title="通用额度设置"
      :visible.sync="TYEddialogVisible"
      width="50%"
      @close="colseDialog"
    >
      <el-row>
        <template>
          <el-select
            v-model="TYEdueryinfo.jj"
            placeholder="请选择操作类型"
            size="medium"
          >
            <el-option
              v-for="item in isJJ"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </el-row>
      <el-row
        ><el-input
          v-model="TYEdueryinfo.gmNum"
          placeholder="请输入数量"
        ></el-input
      ></el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="TYEdsubmit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      TYEdueryinfo:{
        id: "",
        jj: "",
        gmNum: "",
      },
      Edueryinfo: {
        id: "",
        coinId: "",
        jj: "",
        gnNum: "",
      },
      PlEdueryinfo: {
        // coinId: "",
        jj: "",
        type: "",
        gmNum: "",
        values: "",
      },
      YEqueryinfo: {
        smsid: "",
        codes: "",
        coinId: "",
        token: "",
        tokenyy: "",
        isWay: null,
      },
      LRdialogVisible: false,
      centerDialog: false,
      lrdialogVisible: false,
      EddialogVisible: false,
      ZddialogVisible: false,
      PlEddialogVisible: false,
      TYEddialogVisible: false,
      isWays: [
        { value: false, label: "加" },
        { value: true, label: "减" },
      ],
      isJJ: [
        { value: 1, label: "加" },
        { value: 2, label: "减" },
      ],
      isTel: [
        { value: 0, label: "手机" },
        { value: 1, label: "邮箱" },
      ],
      queryinfo: {
        userTel: "",
        userEmail: "",
        pageIndex: 1,
        pageSize: 10,
      },
      total: 0,
      countALL: "",
      countByIsValid: "",
      countByToDay: "",
      tableData: [],
      zcTableData: [],
      lrTableData: [],
      zdTableData: [],
      dialogVisible: false,
      titleText: "",
      changeValue: "",
      userId: "",
      options: [],
      Zdquery: {
        id: "",
        pageIndex: "",
        pageSize: "200",
      },
    };
  },
  created() {
    this.getmsgList();
  },
  methods: {
    // 关闭对话框清空重置
    colseDialog() {
      this.YEqueryinfo.codes = "";
      this.YEqueryinfo.coinId = "";
      this.YEqueryinfo.token = "";
      this.YEqueryinfo.tokenyy = "";
      this.YEqueryinfo.isWay = null;
      this.Edueryinfo.coinId = "";
      this.Edueryinfo.jj = "";
      this.Edueryinfo.gnNum = "";
      this.PlEdueryinfo.coinId = "";
      this.PlEdueryinfo.jj = "";
      this.PlEdueryinfo.type = "";
      this.PlEdueryinfo.gnNum = "";
      this.PlEdueryinfo.values = "";
    },
    // 查看资产
    async lookzc(id) {
      const ids = { userId: id };
      this.dialogVisible = true;
      const { data: res } = await this.$http.post(
        "currencyAudit/getUserAssets",
        this.httputil(ids)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.zcTableData = res.data;
    },
    // 点击添加按钮打开对话框
    async entering(id) {
      this.YEqueryinfo.id = id;
      this.LRdialogVisible = true;
      const { data: res } = await this.$http.post(
        "currencyAudit/getCoinListAll"
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.options = res.data;
    },
    // 获取验证码
    async GetCode() {
      this.centerDialog = true;
      const type = { type: 10 };
      const { data: res } = await this.$http.post(
        "currencyAudit/getSmsCode",
        this.httputil(type)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.YEqueryinfo.smsid = res.data.id;
    },
    // 提交余额录入
    async submit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/InsertBalance",
        this.httputil(this.YEqueryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.LRdialogVisible = false;
      this.centerDialog = false;
      this.getmsgList();
    },
    // 查看录入记录
    async enteringInfo(ids) {
      const id = { id: ids };
      const { data: res } = await this.$http.post(
        "currencyAudit/getjlList",
        this.httputil(id)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.lrdialogVisible = true;
      this.lrTableData = res.data;
    },

    // 调整额度
    async edEntering(ids) {
      this.Edueryinfo.id = ids;
      this.EddialogVisible = true;
      const { data: res } = await this.$http.post(
        "currencyAudit/getCoinListAll"
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.options = res.data;
    },

    // 通用额度设置
    async TYEDset(ids) {
      this.TYEdueryinfo.id = ids;
      this.TYEddialogVisible = true;
    },
    // 通用额度设置
    async TYEdsubmit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/updatePrivateGmNum",
        this.httputil(this.TYEdueryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.TYEddialogVisible = false;
      this.getmsgList();
    },

    // 确认修改额度
    async Edsubmit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/updatePrivateGmNum",
        this.httputil(this.Edueryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.EddialogVisible = false;
      this.getmsgList();
    },

    // 点击批量调整额度
    async PledEntering() {
      this.PlEddialogVisible = true;
      const { data: res } = await this.$http.post(
        "currencyAudit/getCoinListAll"
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.options = res.data;
    },
    // 确认批量调整额度
    async PlEdsubmit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/updatePrivateListGmNum",
        this.httputil(this.PlEdueryinfo)
      );
      if (res.code !== 200) return this.open(res.msg);
      this.$message.success(res.msg);
      this.PlEddialogVisible = false;
      this.getmsgList();
    },
    open(msg) {
      this.$alert(msg, "提示信息", {
        confirmButtonText: "确定",
        callback: (action) => {
          this.$message({
            type: "info",
            message: `请输入正确类型`,
          });
        },
      });
    },
    // 查看账单明细
    async lookZd(id) {
      this.Zdquery.id = id;
      const { data: res } = await this.$http.post(
        "currencyAudit/getCoinOrderList",
        this.httputil(this.Zdquery)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.ZddialogVisible = true;
      this.zdTableData = res.data.list;
    },
    // 获取审核列表
    async getmsgList() {
      const { data: res } = await this.$http.post(
        "currencyAudit/getGxEquity",
        this.httputil(this.queryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.tableData = res.data.UserInfos;
      this.total = res.data.count;
      this.countALL = res.data.countALL;
      this.countByIsValid = res.data.countByIsValid;
      this.countByToDay = res.data.countByToDay;
    },
    // 是否冻结提币
    async Tbsubmit(id, b) {
      if (b == false) {
        b = 1;
      } else {
        b = 0;
      }
      const data = {
        id: id,
        isTb: b,
      };
      const { data: res } = await this.$http.post(
        "currencyAudit/updateUserStatus",
        this.httputil(data)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 是否冻结账户  { id: a, isFreeze: b },
    async Freezesubmit(id, b) {
      if (b == false) {
        b = 1;
      } else {
        b = 0;
      }
      const data = {
        id: id,
        isFreeze: b,
      };
      const { data: res } = await this.$http.post(
        "currencyAudit/updateUserStatus",
        this.httputil(data)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
    },
    // 页面数量发生改变
    handleSizeChange(newSize) {
      this.queryinfo.pageSize = newSize;
      this.getmsgList();
    },
    // 页数发生改变
    handleCurrentChange(newCurrent) {
      this.queryinfo.pageIndex = newCurrent;
      this.getmsgList();
    },
  },
};
</script>
<style lang="less" scoped>
.restyle {
  color: #409eff;
  font-size: 18px;
  font-weight: 600;
}
</style>
